<div id="main">
    <div id="contents">
        <form method="post" name="filters">
            <fieldset>
                <legend>
                    <label sid="tools.td9"></label>
                </legend>
                <div class="frame_tab_layer">
                    <div id="note" class="waiting" style="display: none;">
                        <label sid="msg.datapackWaiting"></label>
                    </div>
                    <table class="cmenutitle" width="100%" cellspacing="0" cellpadding="0" border="0">
                        <tbody>
                        <tr>
                            <td align="center" colspan="2">
                                <input class="button" type="button" name="start" sid="sbutton.start">
                                <input class="button" type="button" name="stop" sid="sbutton.stops">
                            </td>
                        </tr>
                        </tbody>
                    </table>
                </div>
            </fieldset>
        </form>
    </div>
</div>
<br>
<div id="helpContainer">
    <div id="help">
        <div>
            <h2>
                <label sid="share.help"></label>
            </h2>
        </div>
        <dl>
            <dt class="term">
                <label sid="tcpdumpcfg.title1"></label>
            </dt>
            <dd class="definition">
                <label sid="tcpdumpcfg.detail1"></label>
            </dd>
            <dt class="term">
                <label sid="tcpdumpcfg.title2"></label>
            </dt>
            <dd class="definition">
                <label sid="tcpdumpcfg.detail2"></label>
                <label sid="tcpdumpcfg.detail3"></label>
                <label sid="tcpdumpcfg.detail4"></label>
            </dd>
        </dl>
    </div>
</div>

<script type="text/javascript">
    $(document).ready(function(){

        var cannotModify = msg.cannotModify1;
        var success = msg.startSuccess;
        var noComp = msg.noComp;
        var already = msg.alreadyCap;
        var dlfail = msg.downloadFail;

        $("[name=start]").click(function () {
            $.ajax({
                type: "POST",
                url: 'xml',
                data: 'method=gw.command.set&action=tcpdump',
                dataType: 'xml',
                error: function (xml) {
                    $(xml).find('Error').each(function () {
                        var errortext = $(this).attr('msg');
                        //show_message("err",errortext);
                        alert(errortext);
                    });
                },
                success: function (xml) {
                    var stat = $(xml).find('rsp').attr("stat");
                    if (stat == "ok" || stat == "reboot" || stat == "restart") {
                        // show_message("success",success);
                        alert(success);
                    } else if (stat == "fail") {
                        $(xml).find('Error').each(function () {
                            var code = $(this).attr('code');
                            if (code == 4) {
                                // show_message("err",cannotModify);
                                alert(cannotModify);
                            } else if (code == 5) {
                                gotologin();
                            } else if (code == 22) {
                                $("[name=stop]").attr("disabled", true);
                                // show_message("err",noComp);
                                alert(noComp);
                            } else if (code == 24) {
                                //show_message("err",already);
                                alert(already);
                            }
                        });
                    }
                }
            });
        });
        $("[name=stop]").click(function () {
            $.ajax({
                type: "POST",
                url: 'xml',
                data: 'method=gw.command.set&action=stop_tcpdump',
                dataType: 'xml',
                error: function (xml) {
                    $(xml).find('Error').each(function () {
                        var errortext = $(this).attr('msg');
                        //show_message("err",errortext);
                        alert(errortext);
                    });
                },
                success: function (xml) {
                    var stat = $(xml).find('rsp').attr("stat");
                    if (stat == "ok" || stat == "reboot" || stat == "restart") {
                        $("#note").show();
                        $.ajax({
                            type: "POST",
                            url:  '/xml?method=gw.log.download&id=4&tmp=' + Math.random(),
                            dataType: "xml",
                            error: function (xml) {
                                gotologin();
                            },
                            success: function (xml) {
                                var errorcode = $(xml).find('Error').attr('code');
                                if (errorcode == '5') {
                                    gotologin();
                                } else {
                                    $(xml).find('item').each(function () {
                                        var downfilename = $(this).attr('value');
                                        $("#note").hide();
                                        window.location.href = downfilename;

                                    });
                                }
                            }
                        });
                    } else if (stat == "fail") {
                        $(xml).find('Error').each(function () {
                            var code = $(this).attr('code');
                            if (code == 4)
                            // show_message("err",cannotModify);
                                alert(cannotModify);
                            else if (code == 5) gotologin();
                            else
                                alert(dlfail);
                            //show_message("err",dlfail);
                        });
                    }
                }
            });
        });
    });

</script>

